/**   
 * All rights Reserved, Designed By MiGu  
 * Copyright:    Copyright(C) 2016-2020  
 * Company       MiGu  Co., Ltd.
*/
package com.migu.spms.webapi;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.migu.spms.dao.entity.ChangeHistoryCriteria;
import com.migu.spms.service.data.User;
import com.migu.spms.service.inf.IChangeHistoryService;
import com.migu.spms.service.inf.IRequireCommentService;
import com.migu.spms.webapi.data.AddCommentRequest;
import com.migu.spms.webapi.data.ChangeHistoryRequest;
import com.migu.spms.webapi.data.ChangeHistoryResponse;


/**   
 * RequireHandleController类
 * 项目名称:  SPMS功能需求
 * 包名称:    com.migu.spms.webapi   
 * 类名称:    RequireHandleController.java
 * 类描述:    功能需求操作接口
 * 创建人:    wcr   
 * 创建时间:  2017年6月21日 上午11:37:48   
 */
@Controller
@RequestMapping(value = "/requireHandle", produces = "application/json;charset=UTF-8")
public class RequireHandleController extends BaseController {

private static Logger logger = LoggerFactory.getLogger(RequireHandleController.class);
    
    @Resource(name="requireCommentServiceImpl")
    private IRequireCommentService requireCommentService;
    
    @Resource(name="changeHistoryServiceImpl")
    private IChangeHistoryService changeHistoryService;
    /**
     * 添加评论
     * @param req
     * @param resp
     * @param sessionId
     * @return
     * @exception @throws
     */
    @ResponseBody
    @RequestMapping(value = "/addComment")
    public String addComment(HttpServletRequest req, HttpServletResponse resp, String sessionId) throws Exception {
        int code = 200;
        User user = getUserBySession(req, sessionId);
//      if (user == null) {
//          return generateResponse(401);
//      }
        AddCommentRequest comment = ParseMsg(req, AddCommentRequest.class);
        requireCommentService.insertRequireComment(comment, user);
        return generateResponse(code);
    }
    
    /**
     * 查询变更历史
     * @param req
     * @param resp
     * @param sessionId
     * @return
     * @exception @throws
     */
    @ResponseBody
    @RequestMapping(value = "/queryChangeHistory")
    public String queryChangeHistory(HttpServletRequest req, HttpServletResponse resp, String sessionId) throws Exception {
        int code = 200;
        User user = getUserBySession(req, sessionId);
//      if (user == null) {
//          return generateResponse(401);
//      }
        ChangeHistoryRequest msg = ParseMsg(req, ChangeHistoryRequest.class);
        ChangeHistoryCriteria criteria = new ChangeHistoryCriteria();
        criteria.setFunctionRequireId(msg.getFunctionRequireId());
        ChangeHistoryResponse chr = changeHistoryService.selectChangeHistoryDOList(criteria);
        return generateResponse(chr, code);
    }
}
